using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;

namespace zeroflag.Parserz.IDE
{
	public class TokenBox
	{

		public bool Render(Graphics g, int x, int y, ColorCombi colors)
		{
			return this.Render(g, ref x, ref y, colors, this.Token as Character);
		}

		public bool Render(Graphics g, ref int x, ref int y, ColorCombi colors, Character current)
		{
			if (current == null)
				return false;
			//string str = current.Value.ToString();
			//if (str == "\n")
			//    str = @"\n";
			//else if (str == "\r")
			//    str = @"\r";
			//else if (str == "\t")
			//    str = @"\t   ";

			//g.FillRectangle(colors.BackgroundBrush, x, y, this.CharSize.Width * str.Length, y);
			//g.DrawString(current.Value.ToString(), this.Font, this.TextBrush, x, y);
			//if (current.Value == '\n')
			//{
			//    x = 0;
			//    y += this.CharSize.Height;
			//}
			//else
			//{
			//    x += this.CharSize.Width * str.Length;
			//}
			//y += this.CharSize.Height;
			return true;
		}


		#region Properties
		private Token m_Token;
		private ITokenViewController m_Configuration;
		private Color m_BackgroundColor;
		private Color m_ForegroundColor;

		public Color ForegroundColor
		{
			get { return m_ForegroundColor; }
			set { m_ForegroundColor = value; }
		}

		public ITokenViewController Configuration
		{
			get { return m_Configuration; }
			set { m_Configuration = value; }
		}

		public Token Token
		{
			get { return m_Token; }
			set { m_Token = value; }
		}

		public string Text
		{
			get
			{
				if (this.Token is Character)
					return ((Character)this.Token).Value.ToString().Replace("\n", @"\n").Replace("\r", @"\r").Replace("\t", @"\t  ");
				else
					return "";
			}
		}

		public Rectangle Region
		{
			get
			{
				return new Rectangle(this.Location, this.Size);
			}
		}

		Point m_Location = new Point();

		public Point Location
		{
			get { return m_Location; }
			set { m_Location = value; }
		}

		public Size Size
		{
			get
			{
				return new Size(this.Configuration.CharSize.Width * this.Text.Length, this.Configuration.CharSize.Height);
			}
		}
		#endregion Properties
	}
}
